package com.FundamentalDemos.Array;

public class 数组反转 {
    public static void main(String[] args) {
        int[] a = new int[]{10, 20, 30, 40, 50};


        System.out.println("原数组:");
        for (int i = 0; i < a.length; i++) {
            System.out.println("a[" + i + "] = " + a[i]);
        }

        for (int head = 0, tail = a.length - 1, temp = 0; head < tail; head++, tail--) {
            temp = a[head];
            a[head] = a[tail];
            a[tail] = temp;
            /*
            //不借助第三个变量交换二者的值
            int a = -1;
            int b = 2;
            a = a + b;
            b = a - b;
            a = a - b;
            System.out.println("a=" + a + ",b=" + b);//a=2,b=-1
            */
        }

        System.out.println("反转后的数组:");
        for (int i = 0; i < a.length; i++) {
            System.out.println("a[" + i + "] = " + a[i]);
        }


    }
}
